﻿//--------------------------------赵洪科------------------------------------//
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;


/// <summary>
///OrderList 的摘要说明
/// </summary>
public partial class OrderList
{
    DataTableDataContext db = new DataTableDataContext();
    //增加到OrderList
    public int insertTo(int id2, string name, string ad, string ph, decimal pay, string s = "否",string time=null,int score = 0)
    {
        OrderList orderlist = new OrderList
        {
            memberId = id2,
            customerName = name,
            adress = ad,
            phone = ph,
            payment = pay,
            createDate = System.DateTime.Now,
            state = s,
            treadDate =time,
            treadRemark = null,
            nScore = score
        };
        db.OrderList.InsertOnSubmit(orderlist);
        db.SubmitChanges();
        int id = orderlist.orderListId;
        return id;
    }

    //根据会员ID号查找订单
    public IEnumerable<OrderList> returnOrderList(int id1)
    {
        var orderlist = from b in db.OrderList where b.memberId == id1 select b;
        return orderlist;
    }

    //按会员姓名查找
    public IEnumerable<OrderList> returnOrderList1(string name)
    {
        var orderlist = from b in db.OrderList where b.customerName == name select b;
        return orderlist;
    }

    //返回所有订单信息
    public IEnumerable<OrderList> returnOrderList1()
    {
         var orderlist = from b in db.OrderList select b;
         return orderlist;
    }

    //删除订单列表的项
    public void removeFr(int id1)
    {
        var orderlists = from b in db.OrderList where b.orderListId == id1 select b;
        var orderdetails = from r in db.OrderDetail from b in db.OrderList where b.orderListId == id1 && b.orderListId == r.orderListId select r;

        foreach (var orderlist in orderdetails)
        {
            db.OrderDetail.DeleteOnSubmit(orderlist);
            db.SubmitChanges();
        }
        foreach (var orderlist in orderlists)
        {
            db.OrderList.DeleteOnSubmit(orderlist);
            db.SubmitChanges();
        }
    }

    //修改订单的处理状态
    public void modifystate(int id1)
    {
        string state;
        int id;
        string name;
        string adress;
        string phone;
        decimal pay;
        OrderList orderlists = new OrderList();
        foreach (var orderlist in orderlists.returnOrderList(id1))
        {
            state = orderlist.state;
            if (state == "是") return;
            else
            {
                id = orderlist.memberId;
                name = orderlist.customerName;
                adress = orderlist.adress;
                phone = orderlist.phone;
                pay = orderlist.payment;
                insertTo(id, name, adress, phone, pay, "是");
            }
        }
    }

    //修改（填写）订单的发货时间
    public void modifySendTime(int id1, string sendtime)
    {
        int id;
        string name;
        string adress;
        string phone;
        decimal pay;
        OrderList orderlists = new OrderList();
        foreach (var orderlist in orderlists.returnOrderList(id1))
        {
            id = orderlist.memberId;
            name = orderlist.customerName;
            adress = orderlist.adress;
            phone = orderlist.phone;
            pay = orderlist.payment;
            insertTo(id, name, adress, phone, pay, "是", sendtime);
        }

    }
}